package cn.sc.allinpay.allfavour.business.coupon;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import java.math.BigDecimal;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import cn.sc.allinpay.allfavour.R;
import cn.sc.allinpay.allfavour.base.activity.BaseActivity;
import cn.sc.allinpay.allfavour.base.widget.DecorationVert;
import cn.sc.allinpay.allfavour.business.common.adapter.CouponAdapter;
import cn.sc.allinpay.allfavour.business.common.data.CouponsData;


/**
 * activity 券核销
 * author：pany
 * on 2017/12/1 11:14
 */
public class CouponActivity extends BaseActivity<CouponContract.View, CouponContract.Presenter>
        implements CouponContract.View,CouponAdapter.OnAdapterListener {

    @BindView(R.id.recycler)
    RecyclerView recycler;
    @BindView(R.id.tvPaidAmt)
    AppCompatTextView tvPaidAmt;

    private CouponAdapter couponsAdapter;

    @Override
    protected int layoutId() {
        return R.layout.activity_coupon;
    }

    @Override
    protected void layoutTitle(View top, AppCompatTextView left, AppCompatTextView title, AppCompatTextView right) {
        title.setText("券核销");
    }

    @Override
    protected CouponContract.Presenter bindPresenter() {
        return new CouponPresenter();
    }

    @Override
    protected void layoutContent(Bundle savedInstanceState) {
        recycler.addItemDecoration(new DecorationVert(this, R.dimen.margin_common, R.dimen.margin_common));
        recycler.setLayoutManager(new LinearLayoutManager(this));// 列表布局
        couponsAdapter = new CouponAdapter();
        couponsAdapter.setOnAdapterListener(this);
        recycler.setAdapter(couponsAdapter);
    }

    @Override
    public void showPaidAmt(String amt) {
        tvPaidAmt.setText(amt);
    }

    @Override
    public void couponsAdapterChange(List<CouponsData> datas) {
        couponsAdapter.change(datas);
    }

    @Override
    public void saveOrderPaidAmt(BigDecimal paidAmt) {
        SharedPreferences settings = getSharedPreferences("paidAmt", 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("paidAmt",paidAmt.toString());
        editor.commit();
    }

    @Override
    public void onDataChange() {
        presenter.calculateAmt();
    }

    @OnClick(R.id.btnConfirm)
    public void clickConfirm() {
        presenter.setForResult();
    }
}
